package com.chen.internalcommon.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author chenLiuPing
 **/
public class Decimal {

    private BigDecimal decimal;



    public  Decimal add(double v) {
        BigDecimal vBigDecimal = new BigDecimal(v);
        decimal = decimal.add(vBigDecimal);
        return this;
    }

    public  Decimal subtract(double v) {
        BigDecimal vBigDecimal = new BigDecimal(v);
        decimal = decimal.subtract(vBigDecimal);
        return this;
    }

    public  Decimal multiply(double v) {
        BigDecimal vBigDecimal = new BigDecimal(v);
        decimal = decimal.multiply(vBigDecimal);
        return this;
    }

    public Decimal divide(double v) {
        BigDecimal vBigDecimal = new BigDecimal(v);
        decimal = decimal.divide(vBigDecimal, 2, RoundingMode.HALF_UP);
        return this;
    }

    public Decimal(double value) {
        decimal = new BigDecimal(value);
    }

    public double getValue() {
        return decimal.setScale(2, RoundingMode.HALF_UP).doubleValue();
    }

}
